package com.zablert.mainactivity.normal.fragment

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.zablert.mainactivity.R
import com.zablert.mainactivity.databinding.FragmentNormalBinding
import com.zablert.mainactivity.recyclerview.ItemAnimatorAdapter
import com.zablert.mainactivity.recyclerview.ItemAnimatorParam
import zyc.zalbert.fragment.CoreDataBindingFragment
import zyc.zalbert.fragment.CoreFragment
import zyc.zalbert.utils.TestUtils

// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"

/**
 * @Author zyc
 * @CreateDate 2022/1/27
 * @Description
 */
class NormalFragment : CoreDataBindingFragment<FragmentNormalBinding>() {
    // TODO: Rename and change types of parameters
    private var param1: String? = null
    private var param2: String? = null
    private var mAdapter: ItemAnimatorAdapter? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
            param1 = it.getString(ARG_PARAM1)
            param2 = it.getString(ARG_PARAM2)
        }
    }

    override fun onInitContent(savedInstanceState: Bundle?) {
        super.onInitContent(savedInstanceState)
        binding.run {
            tvTitle.text = param1
            rvDemo.layoutManager = LinearLayoutManager(mContext, RecyclerView.VERTICAL, false)
            mAdapter = ItemAnimatorAdapter()
            rvDemo.adapter = mAdapter
            mAdapter?.setItems(TestUtils.forData(ItemAnimatorParam("",""), 20))
        }
    }

    override fun layoutId(): Int {
        return R.layout.fragment_normal
    }

    companion object {
        /**
         * Use this factory method to create a new instance of
         * this fragment using the provided parameters.
         *
         * @param param1 Parameter 1.
         * @param param2 Parameter 2.
         * @return A new instance of fragment NormalFragment.
         */
        // TODO: Rename and change types and number of parameters
        @JvmStatic
        fun newInstance(param1: String, param2: String) =
            NormalFragment().apply {
                arguments = Bundle().apply {
                    putString(ARG_PARAM1, param1)
                    putString(ARG_PARAM2, param2)
                }
            }
    }
}